# electricity consumption data at MSOA level (pre downloaded)
inFile <-paste0(dataFolder, "energy/MSOA_DOM_ELEC_2019.csv")
msoa_elecData <- readr::read_csv(inFile)
##
## ── Column specification ────────────────────────────────────────────────────────
## cols(
## `Local Authority Name` = col_character(),
## `Local Authority Code` = col_character(),
## `MSOA Name` = col_character(),
## `Middle Layer Super Output Area (MSOA) Code` = col_character(),
## `Number of meters` = col_double(),
## `Consumption (kWh)` = col_double(),
## `Mean consumption (kWh per meter)` = col_double(),
## `Median consumption (kWh per meter)` = col_double()
## )
head(msoa_elecData)
## # A tibble: 6 x 8
## `Local Authority N… `Local Authority … `MSOA Name` `Middle Layer Super Outpu…
## <chr> <chr> <chr> <chr>
## 1 Hartlepool E06000001 Hartlepool … E02002483
## 2 Hartlepool E06000001 Hartlepool … E02002484
## 3 Hartlepool E06000001 Hartlepool … E02002485
## 4 Hartlepool E06000001 Hartlepool … E02002487
## 5 Hartlepool E06000001 Hartlepool … E02002488
## 6 Hartlepool E06000001 Hartlepool … E02002489
## # … with 4 more variables: Number of meters <dbl>, Consumption (kWh) <dbl>,
## # Mean consumption (kWh per meter) <dbl>,
## # Median consumption (kWh per meter) <dbl>
inf <-paste0(dataFolder, "boundaries/MSOA/msoa_solent.shp")
message("Loading Middle Layer Super Output Area (MSOA) from file")
## Loading Middle Layer Super Output Area (MSOA) from file
#When using shp files you might also need to have other supplementary files in the same folder to allow it to run https://cfss.uchicago.edu/notes/simple-features/
msoa_sf_data <- sf::read_sf(inf)
head (msoa_sf_data)
## Simple feature collection with 6 features and 13 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: 458985.4 ymin: 102894 xmax: 467725.4 ymax: 107035
## Projected CRS: OSGB 1936 / British National Grid
## # A tibble: 6 x 14
## MSOA11CD MSOA11NM OBJECTID BNG_E BNG_N LONG_ LAT Shape_Leng Shape__Are
## <chr> <chr> <int> <int> <int> <dbl> <dbl> <dbl> <dbl>
## 1 E02003524 Portsmouth… 3510 463726 106331 -1.10 50.9 8175. 1880016.
## 2 E02003525 Portsmouth… 3511 465172 105904 -1.08 50.8 13220. 2012966.
## 3 E02003526 Portsmouth… 3512 466581 106095 -1.06 50.9 10425. 2260228.
## 4 E02003527 Portsmouth… 3513 464176 104420 -1.09 50.8 21957. 3838768.
## 5 E02003529 Portsmouth… 3514 466420 104925 -1.06 50.8 10636. 1499618.
## 6 E02003530 Portsmouth… 3515 465411 103721 -1.07 50.8 13264. 1695461.
## # … with 5 more variables: Shape__Len <dbl>, LAD11CD <chr>, LAD11NM <chr>,
## # nOAs <int>, geometry <MULTIPOLYGON [m]>
table(msoa_sf_data$LAD11NM)#how many MSOAs are in each LA
##
## Basingstoke and Deane East Hampshire Eastleigh
## 22 15 15
## Fareham Gosport Hart
## 14 10 11
## Havant Isle of Wight New Forest
## 17 18 23
## Portsmouth Southampton Test Valley
## 25 32 15
## Winchester
## 14
msoa_elecData$MSOA11CD <- msoa_elecData$ 'Middle Layer Super Output Area (MSOA) Code' #Creating a variable with the LA code and the name as in the sf_data
msoa_merged_sf <-merge(msoa_sf_data, msoa_elecData)
ggplot2::ggplot(msoa_merged_sf) +
geom_sf(aes(fill = `Mean consumption (kWh per meter)`)) +
scale_fill_continuous(name = "Electricity: Mean kWh per meter", low = "green", high = "red") +
labs(caption = "Solent (all MSOAs)")
#mapping it
# gas consumption data at MSOA level (pre downloaded)
inFile <-paste0(dataFolder, "energy/MSOA_GAS_2019.csv")
msoa_gasData <- readr::read_csv(inFile)
##
## ── Column specification ────────────────────────────────────────────────────────
## cols(
## `Local Authority Name` = col_character(),
## `Local Authority Code` = col_character(),
## `MSOA Name` = col_character(),
## `Middle Layer Super Output Area (MSOA) Code` = col_character(),
## `Number of consuming meters` = col_double(),
## `Consumption (kWh)` = col_double(),
## `Mean consumption (kWh per meter)` = col_double(),
## `Median consumption (kWh per meter)` = col_double(),
## `Number of non consuming meters` = col_character()
## )
head(msoa_gasData)
## # A tibble: 6 x 9
## `Local Authority N… `Local Authority … `MSOA Name` `Middle Layer Super Outpu…
## <chr> <chr> <chr> <chr>
## 1 Hartlepool E06000001 Hartlepool … E02002483
## 2 Hartlepool E06000001 Hartlepool … E02002484
## 3 Hartlepool E06000001 Hartlepool … E02002485
## 4 Hartlepool E06000001 Hartlepool … E02002487
## 5 Hartlepool E06000001 Hartlepool … E02002488
## 6 Hartlepool E06000001 Hartlepool … E02002489
## # … with 5 more variables: Number of consuming meters <dbl>,
## # Consumption (kWh) <dbl>, Mean consumption (kWh per meter) <dbl>,
## # Median consumption (kWh per meter) <dbl>,
## # Number of non consuming meters <chr>
msoa_gasData$MSOA11CD <- msoa_gasData$ 'Middle Layer Super Output Area (MSOA) Code'
msoa_merged_sf_domgas <-merge(msoa_sf_data, msoa_gasData)
ggplot2::ggplot(msoa_merged_sf_domgas) +
geom_sf(aes(fill = `Mean consumption (kWh per meter)`)) +
scale_fill_continuous(name = "Gas: Mean kWh per meter", low = "green", high = "red") +
labs(caption = "Solent (all MSOAs)")
#mapping it
Does this match to non-gas areas??
# electricity consumption data for industry at MSOA level (pre downloaded)
inFile <-paste0(dataFolder, "energy/MSOA_NONDOM_2019.csv")
msoa_elecDatanondom <- readr::read_csv(inFile)
##
## ── Column specification ────────────────────────────────────────────────────────
## cols(
## `Local Authority Name` = col_character(),
## `Local Authority Code` = col_character(),
## `MSOA Name` = col_character(),
## `Middle Layer Super Output Area (MSOA) Code` = col_character(),
## `Number of meters` = col_double(),
## `Consumption (kWh)` = col_double(),
## `Mean consumption (kWh per meter)` = col_double(),
## `Median consumption (kWh per meter)` = col_double()
## )
head(msoa_elecDatanondom)
## # A tibble: 6 x 8
## `Local Authority N… `Local Authority … `MSOA Name` `Middle Layer Super Outpu…
## <chr> <chr> <chr> <chr>
## 1 Hartlepool E06000001 Hartlepool … E02002483
## 2 Hartlepool E06000001 Hartlepool … E02002484
## 3 Hartlepool E06000001 Hartlepool … E02002485
## 4 Hartlepool E06000001 Hartlepool … E02002487
## 5 Hartlepool E06000001 Hartlepool … E02002488
## 6 Hartlepool E06000001 Hartlepool … E02002489
## # … with 4 more variables: Number of meters <dbl>, Consumption (kWh) <dbl>,
## # Mean consumption (kWh per meter) <dbl>,
## # Median consumption (kWh per meter) <dbl>
msoa_elecDatanondom$MSOA11CD <- msoa_elecDatanondom$ 'Middle Layer Super Output Area (MSOA) Code'
msoa_merged_sf_nondom <-merge(msoa_sf_data, msoa_elecDatanondom)
ggplot2::ggplot(msoa_merged_sf_nondom) +
geom_sf(aes(fill = `Mean consumption (kWh per meter)`)) +
scale_fill_continuous(name = "Electricity: Mean kWh per meter", low = "green", high = "red") +
labs(caption = "Solent (all MSOAs)")
#mapping it
# gas consumption data for industry at MSOA level (pre downloaded)
inFile <-paste0(dataFolder, "energy/MSOA_NonDom_Gas_2019.csv")
msoa_gasDatanondom <- readr::read_csv(inFile)
##
## ── Column specification ────────────────────────────────────────────────────────
## cols(
## `Local Authority Name` = col_character(),
## `Local Authority Code` = col_character(),
## `MSOA Name` = col_character(),
## `Middle Layer Super Output Area (MSOA) Code` = col_character(),
## `Number of meters` = col_double(),
## `Consumption (kWh)` = col_double(),
## `Mean consumption (kWh per meter)` = col_double(),
## `Median consumption (kWh per meter)` = col_double()
## )
head(msoa_gasDatanondom)
## # A tibble: 6 x 8
## `Local Authority N… `Local Authority … `MSOA Name` `Middle Layer Super Outpu…
## <chr> <chr> <chr> <chr>
## 1 Hartlepool E06000001 Hartlepool … E02002483
## 2 Hartlepool E06000001 Hartlepool … E02002484
## 3 Hartlepool E06000001 Hartlepool … E02002485
## 4 Hartlepool E06000001 Hartlepool … E02002487
## 5 Hartlepool E06000001 Hartlepool … E02002488
## 6 Hartlepool E06000001 Hartlepool … E02002489
## # … with 4 more variables: Number of meters <dbl>, Consumption (kWh) <dbl>,
## # Mean consumption (kWh per meter) <dbl>,
## # Median consumption (kWh per meter) <dbl>
msoa_gasDatanondom$MSOA11CD <- msoa_gasDatanondom$ 'Middle Layer Super Output Area (MSOA) Code'
msoa_merged_sf_nondom_gas <-merge(msoa_sf_data, msoa_gasDatanondom)
ggplot2::ggplot(msoa_merged_sf_nondom_gas) +
geom_sf(aes(fill = `Mean consumption (kWh per meter)`)) +
scale_fill_continuous(name = "Gas: Mean kWh per meter", low = "green", high = "red") +
labs(caption = "Solent (all MSOAs)")
#mapping it
The holes tell you where there is no non-domestic gas use
#Electricty consumption data LSOA pre downloaded
inFile <-paste0(dataFolder, "energy/LSOA_ELEC_2019.csv")
lsoa_elecData <- readr::read_csv(inFile)
##
## ── Column specification ────────────────────────────────────────────────────────
## cols(
## `Local Authority Name` = col_character(),
## `Local Authority Code` = col_character(),
## `Middle Layer Super Output Area (MSOA) Name` = col_character(),
## `Middle Layer Super Output Area (MSOA) Code` = col_character(),
## `Lower Layer Super Output Area (LSOA) Name` = col_character(),
## `Lower Layer Super Output Area (LSOA) Code` = col_character(),
## `Total number of domestic electricity meters` = col_double(),
## `Total domestic electricity consumption (kWh)` = col_double(),
## `Mean domestic electricity consumption
## (kWh per meter)` = col_double(),
## `Median domestic electricity consumption
## (kWh per meter)` = col_double()
## )
lsoa_elecData$LSOA11CD <- lsoa_elecData$`Lower Layer Super Output Area (LSOA) Code`
head(msoa_elecData)
## # A tibble: 6 x 9
## `Local Authority N… `Local Authority … `MSOA Name` `Middle Layer Super Outpu…
## <chr> <chr> <chr> <chr>
## 1 Hartlepool E06000001 Hartlepool … E02002483
## 2 Hartlepool E06000001 Hartlepool … E02002484
## 3 Hartlepool E06000001 Hartlepool … E02002485
## 4 Hartlepool E06000001 Hartlepool … E02002487
## 5 Hartlepool E06000001 Hartlepool … E02002488
## 6 Hartlepool E06000001 Hartlepool … E02002489
## # … with 5 more variables: Number of meters <dbl>, Consumption (kWh) <dbl>,
## # Mean consumption (kWh per meter) <dbl>,
## # Median consumption (kWh per meter) <dbl>, MSOA11CD <chr>
#The LSOA boundaries for the Solent have been pre-downloaded
inf<-paste0(dataFolder, "boundaries/LSOA/lsoa_solent.shp")
message ("Loading LSOA boundaries from file")
## Loading LSOA boundaries from file
lsoa_sf_data <- sf::read_sf(inf)
head(lsoa_sf_data)
## Simple feature collection with 6 features and 15 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: 465991.4 ymin: 100849 xmax: 467770.5 ymax: 102360.8
## Projected CRS: OSGB 1936 / British National Grid
## # A tibble: 6 x 16
## LSOA11CD OBJECTID LSOA11NM LSOA11NMW BNG_E BNG_N LONG LAT Shape__Are
## <chr> <int> <chr> <chr> <int> <int> <dbl> <dbl> <dbl>
## 1 E01017013 16519 Portsmout… Portsmouth… 466127 101741 -1.06 50.8 145134.
## 2 E01017014 16520 Portsmout… Portsmouth… 466924 101957 -1.05 50.8 757371.
## 3 E01017015 16521 Portsmout… Portsmouth… 467084 101499 -1.05 50.8 472647.
## 4 E01017016 16522 Portsmout… Portsmouth… 466330 101597 -1.06 50.8 122927.
## 5 E01017017 16523 Portsmout… Portsmouth… 466813 101069 -1.05 50.8 166924.
## 6 E01017018 16524 Portsmout… Portsmouth… 466350 101184 -1.06 50.8 184945.
## # … with 7 more variables: Shape__Len <dbl>, MSOA11CD <chr>, MSOA11NM <chr>,
## # LAD11CD <chr>, LAD11NM <chr>, nLSOAs <int>, geometry <MULTIPOLYGON [m]>
table(lsoa_sf_data$LAD11NM)#How many LSOAs are there in each LA
##
## Basingstoke and Deane East Hampshire Eastleigh
## 109 72 77
## Fareham Gosport Hart
## 73 53 57
## Havant Isle of Wight New Forest
## 78 89 114
## Portsmouth Southampton Test Valley
## 125 148 71
## Winchester
## 70
lsoa_merged_sf <- merge(lsoa_sf_data, lsoa_elecData) #merging the boundaries and energy data
ggplot2::ggplot(lsoa_merged_sf) +
geom_sf(aes(fill = `Mean domestic electricity consumption \n(kWh per meter)`)) +
scale_fill_continuous(name = "Mean kWh per meter", low = "green", high = "red") +
labs(caption = "Solent (all LSOAs)")
#Mapping it
#Cities such as Southampton disappear due to their density, we will now map Southampton alone to see this area in more detail
mapData <- dplyr::filter(lsoa_merged_sf, LAD11NM == "Southampton")
# plotting the electricity consumption of Southampton in more detail
ggplot2::ggplot(mapData) +
geom_sf(aes(fill = `Mean domestic electricity consumption \n(kWh per meter)`)) +
scale_fill_continuous(name = "Mean kWh per meter", low = "green", high = "red") +
labs(caption = "Southampton")
#Electricty consumption data LSOA pre downloaded
inFile <-paste0(dataFolder, "energy/LSOA_GAS_2019.csv")
lsoa_gasData <- readr::read_csv(inFile)
##
## ── Column specification ────────────────────────────────────────────────────────
## cols(
## `Local Authority Name` = col_character(),
## `Local Authority Code` = col_character(),
## `MSOA Name` = col_character(),
## `Middle Layer Super Output Area (MSOA) Code` = col_character(),
## `LSOA Name` = col_character(),
## `Lower Layer Super Output Area (LSOA) Code` = col_character(),
## `Number of consuming meters` = col_double(),
## `Consumption (kWh)` = col_double(),
## `Mean consumption (kWh per meter)` = col_double(),
## `Median consumption (kWh per meter)` = col_double(),
## `Number of non-consuming meters` = col_character()
## )
lsoa_gasData$LSOA11CD <- lsoa_gasData$`Lower Layer Super Output Area (LSOA) Code`
head(lsoa_gasData)
## # A tibble: 6 x 12
## `Local Authority… `Local Authority… `MSOA Name` `Middle Layer Sup… `LSOA Name`
## <chr> <chr> <chr> <chr> <chr>
## 1 Hartlepool E06000001 Hartlepool… E02002483 Hartlepool…
## 2 Hartlepool E06000001 Hartlepool… E02002483 Hartlepool…
## 3 Hartlepool E06000001 Hartlepool… E02002483 Hartlepool…
## 4 Hartlepool E06000001 Hartlepool… E02002483 Hartlepool…
## 5 Hartlepool E06000001 Hartlepool… E02002483 Hartlepool…
## 6 Hartlepool E06000001 Hartlepool… E02002483 Hartlepool…
## # … with 7 more variables: Lower Layer Super Output Area (LSOA) Code <chr>,
## # Number of consuming meters <dbl>, Consumption (kWh) <dbl>,
## # Mean consumption (kWh per meter) <dbl>,
## # Median consumption (kWh per meter) <dbl>,
## # Number of non-consuming meters <chr>, LSOA11CD <chr>
lsoa_merged_sf_gas <- merge(lsoa_sf_data, lsoa_gasData) #merging the boundaries and energy data
ggplot2::ggplot(lsoa_merged_sf_gas) +
geom_sf(aes(fill = `Mean consumption (kWh per meter)`)) +
scale_fill_continuous(name = "Gas: Mean kWh per meter", low = "green", high = "red") +
labs(caption = "Solent (all LSOAs)")
#Mapping it
Aha - this one shows where there is no gas :-)
didn’t we already do this in the MSOA section?
# electricity consumption data for industry at LSOA level (pre downloaded)
inFile <-paste0(dataFolder, "energy/MSOA_NONDOM_2019.csv")
msoa_elecDatanondom <- readr::read_csv(inFile)
##
## ── Column specification ────────────────────────────────────────────────────────
## cols(
## `Local Authority Name` = col_character(),
## `Local Authority Code` = col_character(),
## `MSOA Name` = col_character(),
## `Middle Layer Super Output Area (MSOA) Code` = col_character(),
## `Number of meters` = col_double(),
## `Consumption (kWh)` = col_double(),
## `Mean consumption (kWh per meter)` = col_double(),
## `Median consumption (kWh per meter)` = col_double()
## )
head(msoa_elecDatanondom)
## # A tibble: 6 x 8
## `Local Authority N… `Local Authority … `MSOA Name` `Middle Layer Super Outpu…
## <chr> <chr> <chr> <chr>
## 1 Hartlepool E06000001 Hartlepool … E02002483
## 2 Hartlepool E06000001 Hartlepool … E02002484
## 3 Hartlepool E06000001 Hartlepool … E02002485
## 4 Hartlepool E06000001 Hartlepool … E02002487
## 5 Hartlepool E06000001 Hartlepool … E02002488
## 6 Hartlepool E06000001 Hartlepool … E02002489
## # … with 4 more variables: Number of meters <dbl>, Consumption (kWh) <dbl>,
## # Mean consumption (kWh per meter) <dbl>,
## # Median consumption (kWh per meter) <dbl>
# Multiple deprivation data at MSOA pre downloaded
inFile <-paste0(dataFolder, "Indices of Multiple Deprivation/Indices_of_Multiple_Deprivation_(IMD)_2019.csv")
lsoa_multidep <- readr::read_csv (inFile)
##
## ── Column specification ────────────────────────────────────────────────────────
## cols(
## `LSOA code (2011)` = col_character(),
## `LSOA name (2011)` = col_character(),
## `Local Authority District code (2019)` = col_character(),
## `Local Authority District name (2019)` = col_character(),
## `Index of Multiple Deprivation (IMD) Rank` = col_number(),
## `Index of Multiple Deprivation (IMD) Decile` = col_double()
## )
head(lsoa_multidep)
## # A tibble: 6 x 6
## `LSOA code (2011… `LSOA name (2011)` `Local Authority Di… `Local Authority Di…
## <chr> <chr> <chr> <chr>
## 1 E01000001 City of London 00… E09000001 City of London
## 2 E01000002 City of London 00… E09000001 City of London
## 3 E01000003 City of London 00… E09000001 City of London
## 4 E01000005 City of London 00… E09000001 City of London
## 5 E01000006 Barking and Dagen… E09000002 Barking and Dagenham
## 6 E01000007 Barking and Dagen… E09000002 Barking and Dagenham
## # … with 2 more variables: Index of Multiple Deprivation (IMD) Rank <dbl>,
## # Index of Multiple Deprivation (IMD) Decile <dbl>
lsoa_multidep$LSOA11CD <- lsoa_multidep$`LSOA code (2011)` #creating a variable with the LSOA code in the same name as in sf_data
head(lsoa_multidep)
## # A tibble: 6 x 7
## `LSOA code (2011… `LSOA name (2011)` `Local Authority Di… `Local Authority Di…
## <chr> <chr> <chr> <chr>
## 1 E01000001 City of London 00… E09000001 City of London
## 2 E01000002 City of London 00… E09000001 City of London
## 3 E01000003 City of London 00… E09000001 City of London
## 4 E01000005 City of London 00… E09000001 City of London
## 5 E01000006 Barking and Dagen… E09000002 Barking and Dagenham
## 6 E01000007 Barking and Dagen… E09000002 Barking and Dagenham
## # … with 3 more variables: Index of Multiple Deprivation (IMD) Rank <dbl>,
## # Index of Multiple Deprivation (IMD) Decile <dbl>, LSOA11CD <chr>
lsoa_multidep_merged_sf <- merge(lsoa_sf_data, lsoa_multidep) #merging these
ggplot2::ggplot(lsoa_multidep_merged_sf) +
geom_sf(aes(fill=`Index of Multiple Deprivation (IMD) Rank`))+ # which data set has the scores?
scale_fill_continuous(name="IMD Rank", low="green",high="red")+
labs(caption ="Solent (all MSOAs)")
R.Version()
## $platform
## [1] "x86_64-apple-darwin17.0"
##
## $arch
## [1] "x86_64"
##
## $os
## [1] "darwin17.0"
##
## $system
## [1] "x86_64, darwin17.0"
##
## $status
## [1] ""
##
## $major
## [1] "4"
##
## $minor
## [1] "0.2"
##
## $year
## [1] "2020"
##
## $month
## [1] "06"
##
## $day
## [1] "22"
##
## $`svn rev`
## [1] "78730"
##
## $language
## [1] "R"
##
## $version.string
## [1] "R version 4.0.2 (2020-06-22)"
##
## $nickname
## [1] "Taking Off Again"